package com.icode.jqgrid;

import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ZhongGang
 * Date: 14-9-8
 * Time: 下午9:31
 */
public class ResultSetServlet extends HttpServlet {
    private static ResultSet resultSet = new ResultSet();

    static {
        List<Person> results = resultSet.getResults();
        for (int i = 0; i < 235; i++) {
            results.add(new Person(i, "ZhongGang" + i, "18583912057", "120859274@qq.com"));
        }
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer currentPage = Integer.valueOf(req.getParameter("page"));
        resultSet.setCurrentPage(currentPage);
        resp.setContentType("application/json");
        PrintWriter writer = resp.getWriter();
        writer.println(JSON.toJSONString(resultSet));
    }
}
